package com.zxl.admin.controller.order;

import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.zxl.admin.service.BookOrderService;
import com.zxl.common.Page;
import com.zxl.common.Result;
import com.zxl.common.model.bo.order.BookOrderApply;
import com.zxl.common.model.bo.order.BookOrderAuditStatus;
import com.zxl.common.model.query.order.BookOrderQuery;
import com.zxl.common.model.vo.member.MemberInfoDetailVo;
import com.zxl.common.model.vo.order.BookOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zxw
 * @date 2023/4/1
 */
@Api(tags = "申请订货管理")
@RestController
@RequestMapping("/admin/book_order")
public class BookOrderController {
    @Resource
    private BookOrderService bookOrderService;

    @GetMapping("/select")
    @ApiOperation("申请订货列表")
    public Result<Page<BookOrderVo>> getBookOrderList(BookOrderQuery bookOrderQuery){
        List<BookOrderVo> bookOrderList = bookOrderService.getBookOrderList(bookOrderQuery);
        Page<BookOrderVo> page = Page.pageInfoConvert(new PageInfo(bookOrderList));
        return new Result(page);
    }

    @PostMapping("/update")
    @ApiOperation("修改申请订货审核状态")
    public Result updateBookAuditStatus(BookOrderAuditStatus bookOrderAuditStatus){
        bookOrderService.updateBookAuditStatus(bookOrderAuditStatus);
        return Result.success();
    }

    @GetMapping("/query_member")
    @ApiOperation("查询会员列表")
    public Result queryMember(@RequestParam("nickName") String nickName){
        List<MemberInfoDetailVo> list = bookOrderService.queryMember(nickName);
        return new Result(list);
    }

    @PostMapping("/addBookOrder")
    @ApiOperation("新增订货信息")
    public Result addBookOrder(@RequestBody @Valid BookOrderApply bookOrderApply){
        bookOrderService.addBookOrder(bookOrderApply);
        return Result.success();
    }

    @PostMapping("/updateBookOrder")
    @ApiOperation("修改订货信息")
    public Result updateBookOrder(@RequestBody @Valid BookOrderApply bookOrderApply){
        bookOrderService.updateBookOrder(bookOrderApply);
        return Result.success();
    }
}
